<template>
    <el-container class="home">
<!--      头部-->
      <el-header>
        <div>
          <img src="../assets/logo.jpg" alt="">
          <span>抖音电商后台管理系统</span>
        </div>
        <el-button @click="loginOut">退出</el-button>
      </el-header>
      <el-container>
<!--        侧边栏-->
        <el-aside width="200px">
          <el-menu class="el-menu-vertical-demo" unique-opened router >
            <el-submenu :index="item.id +''" v-for="(item,index) in menuList" :key="item.id">
              <template slot="title">
                <i :class="iconPath[index]"></i>
                <span>{{ item.authName }}</span>
              </template>
<!--              二级菜单-->
              <el-menu-item v-for="(group,index) in item.children" :index="group.path" >
                <template>
                  <i class="el-icon-menu"></i>
                <span>{{ group.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
<!--        主体区域-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
export default {
  data(){
    return{
      menuList:[],
      iconPath:["el-icon-user-solid","el-icon-s-check","el-icon-s-goods","el-icon-s-order","el-icon-s-marketing"]
    }
  },
  created() {
    this.getMenuList()
  },
  name: "home.vue",
  methods:{
    loginOut(){
      window.sessionStorage.clear();
      this.$router.push('/login')
    },
     async getMenuList(){
      const { data: res } =await this.$http.get('menus')
       if(res.meta.status !== 200){return this.$message.error(res.meta.msg)}
       this.menuList = res.data
    },

  }
}
</script>

<style scoped>
.home{
  height: 100%;
}
.el-header{
  background-color: #F5F5F5;
}
.el-header div{
  float: left;
  height: 60px;
  width: 740px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-header .el-button{
  float: right;
  line-height: 30px;
}
.el-header .span{
  line-height: 60px;
  margin: 0 auto;
  font-size: 30px;
}
.el-header img{
  height: 60px;
  opacity: 90%;
}
.el-aside{
  background-color:white;
}
.el-aside .el-menu{
  border-right:none;
}
.el-main{
  background-color: #f5f2f0;

}
</style>